package Demo03;

public class Test {
    public static void main01(String[] args) {
    Ag<Integer> ag = new Ag<>();
    Integer[] integers = {1,2,3,4,5,6};
    Integer res = ag.FindMax(integers);
    System.out.println(res);

    Ag<Person> ag1 = new Ag<>();
}
    public static void main(String[] args) {
        Ag2 ag2 = new  Ag2();
        Integer[] integers = {1,2,3,4};
        Integer res = ag2.<Integer>FindMax(integers);
        System.out.println(res);
    }

}

class Ag2 {
    public<T extends Comparable<T>> T FindMax(T[] arr) {
        T max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(max.compareTo(arr[i]) < 0) {
                max = arr[i];
            }
        }
        return max;
    }
}
class Ag3 {
    public static <T extends Comparable<T>> T FindMax(T[] arr) {
        T max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(max.compareTo(arr[i]) < 0) {
                max = arr[i];
            }
        }
        return max;
    }
}
class Person implements Comparable<Person>{
    @Override
    public int compareTo(Person o) {
        return 0;
    }
}

//写一个泛型类,求数组最大值

class Ag<T extends Comparable<T>> {
    public T FindMax(T[] arr) {
        T max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(max.compareTo(arr[i]) < 0) {
                max = arr[i];
            }
        }
        return max;
    }
}

